package com.mc.main;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * This view draws the background and grid for the simple graph
 * 
 * @author Mikael Bertlin
 *
 */

public class SimpleGraphBgView extends View{
	
	private Paint graphGridPaint;
	private Paint graphGridPaintThick;
	private Paint graphGridPaintThickLight;
	private Paint graphGridHeadingPaint;
	
	int width = 320;
	int height = 480;

	public SimpleGraphBgView(Context context, AttributeSet attrs) {
		super(context, attrs);	
		Resources res = this.getContext().getResources();
		
		int graphGrid = res.getColor(R.color.simplegGraphGrid);
        graphGridPaint = new Paint();
        graphGridPaint.setColor(graphGrid);
        graphGridPaint.setTextSize(22);
        graphGridPaint.setAntiAlias(true);
        
        graphGridHeadingPaint = new Paint();
        graphGridHeadingPaint.setColor(graphGrid);
        graphGridHeadingPaint.setTextSize(30);
        graphGridHeadingPaint.setAntiAlias(true);
        
        int fingerLine = res.getColor(R.color.simpleFingerLine);
        graphGridPaintThick = new Paint();
        graphGridPaintThick.setColor(fingerLine);
        graphGridPaintThick.setStrokeWidth(3);
        
        int fingerLineLight = res.getColor(R.color.simpleFingerLineLighter);
        graphGridPaintThickLight = new Paint();
        graphGridPaintThickLight.setColor(fingerLineLight);
        graphGridPaintThickLight.setStrokeWidth(3);
        
	}

    protected void onDraw(Canvas canvas) {
    	
    	canvas.drawText("-- DataGraph --", (width / 2) - 100, 40, graphGridHeadingPaint);
    	canvas.drawText("200", width-42, 80, graphGridPaint);
    	canvas.drawLine(0,87,width,87, graphGridPaintThickLight);
    	canvas.drawLine(0,90,width,90, graphGridPaintThick);
    	canvas.drawText("160", width-42, 123, graphGridPaint);
    	canvas.drawLine(10,130,width-10,130, graphGridPaint);
    	canvas.drawText("120", width-42, 163, graphGridPaint);
    	canvas.drawLine(10,170,width-10,170, graphGridPaint);
    	canvas.drawText("80", width-33, 203, graphGridPaint);
    	canvas.drawLine(10,210, width-10,210, graphGridPaint);
    	canvas.drawText("40", width-33, 243, graphGridPaint);
    	canvas.drawLine(10,250,width-10,250, graphGridPaint);
    	canvas.drawText("0", width-20, 280, graphGridPaint);
    	canvas.drawLine(0,287,width,287, graphGridPaintThickLight);
    	canvas.drawLine(0,290,width,290, graphGridPaintThick);
    	
    }
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    	// TODO Auto-generated method stub
    	super.onSizeChanged(w, h, oldw, oldh);
    	width = w;
    	height = h;
    }
}
